package com.helloniu.wb.containers 	{

import com.helloniu.data.wb.info.*;	
import com.helloniu.fl.util.*;
import com.helloniu.wb.tools.DrawingTool;
import com.helloniu.wb.tools.TextTool;

import flash.events.MouseEvent;
import flash.geom.Point;
	
public class DrawingToolUtil {
	public function DrawingToolUtil() {
	}
		
	public static function createDrawingTool(shapeType:int):DrawingTool {
		var className:String = ShapeTypeDef.getShapeClassName(shapeType);
    	var obj:DrawingTool = Class2.newInstance(className) as DrawingTool;
		return obj;
	}
	
	public static function createDrawingTool2(shapeType:int):DrawingTool {
		var clazz:Class = ShapeTypeDef.getShapeClass(shapeType);
    	var obj:DrawingTool = Class2.newInstance2(clazz) as DrawingTool;
		return obj;
	}
	
	public static function createShapeInfo(dtool:DrawingTool):ShapeInfo {
		// @temp tonyy
		return null;
	}

    public static function isNewToolValid(newTool:DrawingTool):Boolean {
        if(newTool is TextTool) {
            //return true;
        }

        var arr:Array = newTool.getShapePoints();

        if(arr.length < 2) {
            return false;
        }

        if(arr.length == 2) {
            if(Point.distance(arr[0] as Point, arr[1] as Point) < 10) {
               return false;
            }
        }

        return true;
    }		
    
	public static function createTool(toolType:Number, event:MouseEvent):DrawingTool{		
		var classStr:String = ShapeTypeDef.getShapeClassName(toolType);		
        var newClass:DrawingTool = Class2.newInstance(classStr) as DrawingTool;

        newClass.setStartPoint(new Point(event.localX, event.localY));
        newClass.setEndPoint(new Point(event.localX, event.localY));
        newClass.invalidateDisplayList();

        return newClass;
    }

    /**
     * createStaticTool is used when you want to add a tool to the
     * display list without a mouse event
     * say your surrounding a image to create a halo type effect of some sort
     * you can just pass an sP,eP (startPoint) and (endPoint) and of course
     * if you look in the flex doces you find that a point is a holder for x and y pairs
     **/
    public static function createStaticTool(className:Class, sP:Point, eP:Point):DrawingTool {
        var newClass:DrawingTool = new className();

        newClass.setStartPoint(sP);
        newClass.setEndPoint(eP);

        newClass.invalidateDisplayList();

        return newClass;
    }
/*
    public static function removeTool(blankPaperWrapper:BlankPaperWrapper, drawingTool:DrawingTool):void{
        //loop through the array of children tools to remove it from the array
        for (var i:int = 0; i < blankPaperWrapper.aChildrenTools.length; i++){
            if(blankPaperWrapper.aChildrenTools.getItemAt(i) == drawingTool){
                blankPaperWrapper.aChildrenTools.removeItemAt(i);
            }
        }

        //trace(blankPaperWrapper.aChildrenTools.length);
        blankPaperWrapper.removeChild(drawingTool);
        blankPaperWrapper.selectedItem = null;
    }

    public static function removeAllTools(blankPaperWrapper:BlankPaperWrapper):void {
        //loop through the array of children tools to remove it from the array
        for (var i:int = blankPaperWrapper.aChildrenTools.length - 1; i >= 0; i--){
            blankPaperWrapper.removeChild(blankPaperWrapper.aChildrenTools.getItemAt(i) as DrawingTool);
            blankPaperWrapper.aChildrenTools.removeItemAt(i);
        }

        blankPaperWrapper.selectedItem = null;
    }
    */    		

}
}